﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PSTS.Models
{
    /// <summary>
    /// Data model for questions
    /// </summary>
    public class Question
    {
        /// <summary>
        /// Don`t set it. It will be setted automaticaly at Repository
        /// </summary>
        public int Id { get; set; }   // question id in database

        public string Text { get; set; }   // question content
        public List<string> Answers { get; set; } // list of possible answers
        public int CorrectAnsIndex { get; set; } // position of correct answer at list of possible answers
        public int TopicId { get; set; } // id of question`s topic

        public List<Answer> GetListOfAnswers()
        {
            var result = new List<Answer>();
            if (Answers != null)
            {
                foreach (var answer in Answers)
                {
                    if (Answers.IndexOf(answer) == CorrectAnsIndex)
                        result.Add( new Answer { Value = answer, IsCorrect = true });
                    else
                        result.Add( new Answer { Value = answer, IsCorrect = false });
                }
            }
            return result;
        }
    }
}
